package com.ukao.steward.base;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.sunmi.payservice.hardware.aidl.HardwareOpt;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.ukao.steward.R;
import com.ukao.steward.ui.login.LoginActivity;
import com.ukao.steward.ui.main.MainActivity;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.Utils;

import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;


/**
 * Created by ukaodev on 2017/5/20.
 */

public class BaseApplication extends Application {

    public static HardwareOpt mHardwareOpt;

    @Override
    public void onCreate() {
        super.onCreate();
        /*极光推送*/
        JPushInterface.setDebugMode(false);
        JPushInterface.init(this);

        setStyleBasic();
//        /*极光统计*/
//        JAnalyticsInterface.init(this );
//        JAnalyticsInterface.setDebugMode(false);
        Utils.init(this);
        checkUpdates();
        checkLeakCanary();


    }


    /**
     * 内存泄漏检查
     */
    void checkLeakCanary() {
        //        if (LeakCanary.isInAnalyzerProcess(this)) {
//            // This process is dedicated to LeakCanary for heap analysis.
//            // You should not init your app in this process.
//            return;
//        }
//        LeakCanary.install(this);
    }

    void checkUpdates() {

        // 设置是否开启热更新能力，默认为true
        Beta.enableHotfix = true;
        // 设置是否自动下载补丁
        Beta.canAutoDownloadPatch = true;
        // 设置是否提示用户重启
        Beta.canNotifyUserRestart = true;
        // 设置是否自动合成补丁
        Beta.canAutoPatch = true;
        //Bugly.setIsDevelopmentDevice(getApplicationContext(), true);   开发设备

        /**
         * 只允许在MainActivity上显示更新弹窗，其他activity上不显示弹窗;
         * 不设置会默认所有activity都可以显示弹窗;
         */

//
        Beta.autoCheckUpgrade = CheckUtils.isMIUIDevices() ? false : true;
        Beta.initDelay = 100;/*设置启动延时为1s（默认延时3s），APP启动1s后初始化SDK，避免影响APP启动速度*/
        if (!CheckUtils.isMIUIDevices()) {
            Beta.canShowUpgradeActs.add(MainActivity.class);
            Beta.canShowUpgradeActs.add(LoginActivity.class);
        }

        Bugly.init(getApplicationContext(), "354f51bab7", true);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        // you must install multiDex whatever tinker is installed!
        MultiDex.install(base);
        // 安装tinker
        Beta.installTinker();
    }


    /**
     * 设置通知提示方式 - 基础属性
     */
    private void setStyleBasic() {
        CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text);
        builder.statusBarDrawable = R.mipmap.ic_launcher;
        builder.layoutIconDrawable = R.mipmap.ic_launcher;
        JPushInterface.setPushNotificationBuilder(2, builder);
    }

}
